#ifndef _BIZ_H_INCLUDED_
#define _BIZ_H_INCLUDED_
#include <string>
#include "json.hpp"
using std::string;
#include "capitalism/core.h"
#include <dirent.h>
const int max_waiting_tasks = 20;
const string script_root_path = "user_scripts/";
const string script_output_root_path = "user_outputs/";
class biz
{
private:
    string data;
    core_data_t& core_data;
    connection_t* connection;
    using json = nlohmann::json;
public:
    inline biz(core_data_t& core_data, connection_t* conn):
    data(conn->reader->data), core_data(core_data), connection(conn)
    {
        if(opendir(script_root_path.c_str()) == NULL){
            if(mkdir(script_root_path.c_str(),0777) < 0)
                perror("无法创建用户脚本目录");
        }
        if(opendir(script_output_root_path.c_str()) == NULL){
            if(mkdir(script_output_root_path.c_str(),0777) < 0)
                perror("无法创建用户输出目录");
        }
    }
    biz() = delete;
    void run();
    void scriptExecution(json userData);
    void inspector(const char* outputPath, json userData);
    ~biz() = default;
};



#endif